//
// Created by wujehy on 18-11-14.
//

#include "RunCar.h"
#include "AFMotor.h"

AF_DCMotor motorLeft(1);
AF_DCMotor motorRight(2);

RunCar RunCar::setSpeed(uchar speed) {
    RunCar::speed = speed;
    return *this;
}


void RunCar::ForWard() {
    ForWardLeftSpeed(speed);
    ForWardRightSpeed(speed);
}

void RunCar::BackWard() {

    BackWardLeftSpeed(speed);
    BackWardRightSpeed(speed);
}

void RunCar::ForWardAndLeftHand() {
    ForWardLeftSpeed(speed-level);
    ForWardRightSpeed(speed);
}

void RunCar::ForWardAndRightHand() {
    ForWardLeftSpeed(speed);
    ForWardRightSpeed(speed-level);
}

void RunCar::BackWardAndLeftHand() {
    BackWardLeftSpeed(speed-level);
    BackWardRightSpeed(speed);
}

void RunCar::BackWardAndRightHand() {
    BackWardLeftSpeed(speed);
    BackWardRightSpeed(speed-level);
}

void RunCar::ForWardLeftSpeed(uchar Speed) {
    motorLeft.setSpeed(Speed);
    motorLeft.run(FORWARD);
}

void RunCar::ForWardRightSpeed(uchar Speed) {
    motorRight.setSpeed(Speed);
    motorRight.run(FORWARD);
}

void RunCar::BackWardLeftSpeed(uchar Speed) {
    motorLeft.setSpeed(Speed);
    motorLeft.run(BACKWARD);
}

void RunCar::BackWardRightSpeed(uchar Speed) {
    motorRight.setSpeed(Speed);
    motorRight.run(BACKWARD);
}

void RunCar::Stop() {
    motorRight.setSpeed(0);
    motorRight.run(RELEASE);
    motorLeft.setSpeed(0);
    motorLeft.run(RELEASE);
}

RunCar::RunCar() {
    setSpeed(0);
    setLevel(0);
}

RunCar RunCar::setLevel(unsigned char level) {
    RunCar::level = level;
    return *this;
}


RunCar RunCar::MoreLevel() {
    setSpeed(250);
    setLevel(200);
    return *this;
}

RunCar RunCar::HighLevel() {
    setLevel(150);
    setSpeed(210);
    return *this;
}

RunCar RunCar::MiddleLevel() {
    setSpeed(170);
    setLevel(120);
    return *this;
}

RunCar RunCar::LowLevel() {
    setLevel(60);
    setSpeed(110);
    return *this;
}
